package com.leyou.item.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.apache.ibatis.annotations.Options;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author: wangzibeng
 * Date: 2019/4/28 0028
 * Time: 12:42
 */

@RestController
@RequestMapping("category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByPid(@RequestParam(value = "pid", defaultValue = "0") Long pid) {
        return ResponseEntity.ok(categoryService.queryCategoryByPid(pid));
    }

    @PostMapping("add")
    public ResponseEntity<Long> addCategory(@RequestParam("name") String name, @RequestParam("parentId") Long parentId, @RequestParam("isParent") Boolean isParent, @RequestParam("sort") Integer sort) {
        return ResponseEntity.ok(categoryService.addCategory(name, parentId, isParent, sort));
    }

}
